package day10;

import com.sun.security.ntlm.Server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class SocketDemo {
    public static void main(String[] args) {
        //6666不能用
        try {
            ServerSocket st=new ServerSocket(8888);
            System.out.println("服务器启动鸟");
            while (true){
                //接受请求
                Socket s = st.accept();
                System.out.println("有人连接了。。"+s);
                System.out.println(s.getPort()+","+s.getInetAddress());
                InputStream in = s.getInputStream();
                OutputStream out = s.getOutputStream();
                int ch=-1;
                //in.avaiable不可用
                while ((ch=in.read())!=-1){
                    System.out.print((char)ch);
                }
                s.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
